<?php


Route::get('/test', 'TestController@index');
Route::get('/any', 'TestController@anyData');
Route::group(['prefix'=>'member','middleware'=>'loginAuth'],function(){

    Route::get('/userAddIndex', function () {
        return view('archive.userAddIndex');
    })->name('userAddIndex');


    Route::get('/tags', 'Tag\TagController@index')->name('tag.index');

    //主播标签
    Route::get('/lives', 'Tag\LiveController@index')->name('tag.lives');
    Route::get('/lives/{anchor_id}/edit', 'Tag\LiveController@edit')->name('tag.lives.edit');

    Route::get('/tag/create', 'Tag\TagController@create')->name('tag.create');
    Route::post('/tag/store', 'Tag\TagController@store')->name('tag.store');
    Route::get('/tag/{tag_name}/edit', 'Tag\TagController@edit')->name('tag.edit');
    Route::get('/tag/{tag_name}/status/{code}', 'Tag\TagController@status')->name('tag.status');

    Route::post('/tag/{tag_name}/update', 'Tag\TagController@update')->name('tag.update');

    Route::post('/tag/{tag_name}/attribute', 'Tag\TagController@attrUpdate')->name('tag.attribute.update');
    Route::delete('/tag/attribute/{attr_id}', 'Tag\TagController@attrDelete')->name('tag.attribute.delete');
    Route::post('/tag/extract', 'Tag\TagController@extractTags')->name('tag.extract');

    Route::bind('tag_name', function ($name) {
        return App\Models\Tag\Tag::where('pinyin', $name)
            ->orWhere('id', $name)
            ->firstOrFail();
    });

    Route::bind('attr_id', function ($id) {
        return App\Models\Tag\TagAttribute::find($id);
    });

    Route::get('archives/{left?}', 'Archive\ArchiveController@index')->name('archives.index');
    //Route::resource('archives', 'Archive\ArchiveController');
    Route::post('archives/upload', 'Archive\ArchiveController@upload')->name('archives.upload');
    Route::get('archives/create/{archive_type}', 'Archive\ArchiveController@create')->name('archives.create');
    Route::post('archives/{archive_type}', 'Archive\ArchiveController@store')->name('archives.store');
    Route::put('archives/{archive}', 'Archive\ArchiveController@update')->name('archives.update');

    Route::get('archives/{archive}/toggle/{name}', 'Archive\ArchiveController@toggle')->name('archives.toggle');
    Route::get('archives/{archives}/set/{name}', 'Archive\ArchiveController@setPattern')->name('archives.set.pattern');

    Route::get('archives/destroy/{archives}', 'Archive\ArchiveController@destroy')->name('archives.destroy');
    Route::get('archives/modDestroy/{archives}', 'Archive\ArchiveController@modDestroy')->name('archives.modDestroy');
    Route::post('archive/restore', 'Archive\ArchiveController@restore');
    Route::get('archives/{archive}/{user_type}/edit', 'Archive\ArchiveController@edit')->name('archives.edit');
    //微信采集
    Route::get('wechat/index','Archive\WeChatController@index')->name('wechat.index');
    Route::get('wechat/start','Archive\WeChatController@spiderStart')->name('spider_start');
    Route::get('wechat/stop','Archive\WeChatController@spiderStop')->name('spider_stop');
    Route::put('wechat/update/{archive}','Archive\WeChatController@update')->name('wechat.update');
    Route::get('wechat/txt/{count}','Archive\WeChatController@getTxt')->name('wechat.txt');

    Route::get('lives/download/{count}', 'Tag\LiveController@download')->name('lives.download');


    Route::get('/plupload', function (){
        return view('archive.plupload');
    })->name('archives.plupload');

    Route::bind('archive_type', function ($type_name) {
        if ($type_name) {
            return App\Models\Archive\ArchiveType
                ::where("name", $type_name)
                ->firstOrFail();
        } else {
            return App\Models\Archive\ArchiveType::find(1);
        }
    });
});


Route::group(['domain' => 'www.qiyiguo.tv','middleware'=>'domainAuth'], function () {

    Route::get('/tag/{tag}/{type?}', 'TagHeadController@index')->name('tag.list');

    Route::bind('tag', function ($name) {
        $tag = App\Models\Tag\Tag::where('pinyin', $name)->first();
        return $tag ? $tag : App\Models\Tag\Tag::where('abbr', $name)->firstOrFail();
    });

    Route::get('/archive/like/{archive}', 'Home\contentController@like')->name('archive.like');

    Route::get('/gallery', 'Home\GalleryController@index')->name('galleries.index');
    Route::get('/gallery/{archive}', 'Home\GalleryController@show')->name('galleries.show');
    Route::get('/gallery/cate/{cate}', 'Home\GalleryController@index')->name('galleries.cate');

    Route::get('/author/{user}/{type?}', 'Home\IndexController@author')->name('author.index');


    Route::get('/{uri}/{size}.jpg', '\App\Helpers\UploadFile@read')->name('image')->where(['uri' => '.+']);
    //微信采集接收webhook
    Route::any('wechat/webhook','Archive\WeChatController@webhook');
//自定义路径解析
    Route::get('/{defined}', function (\Illuminate\Http\Request $request, $url) {
        $url = explode('/', $url);
        $tag = \App\Models\Tag\Tag::where('current_url', '/'.$url[0])->first();
        $type = isset($url[1]) ? $url[1] : '';
        return $tag ? (new \App\Http\Controllers\TagHeadController)->index($request, $tag, $type) : abort(404, 'Not Found');
    })->where(['defined' => '.+']);
});

Route::group(['domain' => 'm.qiyiguo.tv','middleware'=>'domainAuth2'], function () {

    Route::get('/tag/{tag}/{type?}', 'TagHeadController@index')->name('tag.list');

    Route::bind('tag', function ($name) {
        $tag = App\Models\Tag\Tag::where('pinyin', $name)->first();
        return $tag ? $tag : App\Models\Tag\Tag::where('abbr', $name)->firstOrFail();
    });

    Route::get('/gallery', 'Home\GalleryController@index')->name('galleries.index');
    Route::get('/gallery/{archive}', 'Home\GalleryController@show')->name('galleries.show');
    Route::get('/gallery/cate/{cate}', 'Home\GalleryController@index')->name('galleries.cate');



    Route::get('/{uri}/{size}.jpg', '\App\Helpers\UploadFile@read')->name('image_m')->where(['uri' => '.+']);
    //微信采集接收webhook
    Route::post('wechat/webhook','Archive\WeChatController@webhook');
//自定义路径解析
    Route::get('/{defined}', function (\Illuminate\Http\Request $request, $url) {
        $url = explode('/', $url);
        $tag = \App\Models\Tag\Tag::where('current_url', '/'.$url[0])->first();
        $type = isset($url[1]) ? $url[1] : '';
        return $tag ? (new \App\Http\Controllers\TagHeadController)->index($request, $tag, $type) : abort(404, 'Not Found');
    })->where(['defined' => '.+']);
});